/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.tree.sort;

import javax.swing.Icon;

import twaver.TDataBox;
import twaver.TWaverUtil;
import twaver.Node;

public class DataFactory {
	
	public final static String DELTA_UP = "UP";
	public final static String DELTA_UPUP = "UPUP";
	public final static String DELTA_DOWN = "DOWN";
	public final static String DELTA_DOWNDOWN = "DOWNDOWN";
	public final static String DELTA_SAME = "SAME";
	
	public final static String PositionDec2004 = "PosDec2004";
	public final static String PositionDec2005 = "PosDec2005";
	public final static String Language = "Language";
	public final static String Delta = "Delta";
	public final static String RatingsDec2005 = "RatingsDec2005";
	public final static String DeltaDec2004 = "DeltaDec2004";
	public final static String Status = "Status";
	
	private static TDataBox box;

	public static void createData(TDataBox box){
		DataFactory.box = box;
		createLanguage(1, 2, DELTA_UP, "Java", 22.129, 5.8, "A"); 
		createLanguage(2, 1, DELTA_DOWN, "C", 19.632, 0.06, "A"); 
		createLanguage(3, 3, DELTA_SAME, "C++", 11.026, -0.89, "A"); 
		createLanguage(4, 4, DELTA_SAME, "PHP", 9.629, -1.76, "A"); 
		createLanguage(5, 5, DELTA_SAME, "Visual Basic", 8.710, 0.54, "A"); 
		createLanguage(6, 6, DELTA_SAME, "Perl", 7.393, -0.03, "A"); 
		createLanguage(7, 9, DELTA_UPUP, "C#", 3.310, 1.36, "A");  
		createLanguage(8, 7, DELTA_DOWN, "Python", 2.678, -0.35, "A");  
		createLanguage(9, 11, DELTA_UPUP, "JavaScript", 1.838, 0.24, "A");  
		createLanguage(10, 8, DELTA_DOWNDOWN, "Delphi/Kylix", 1.426, -1.55, "A");  
		createLanguage(11, 12, DELTA_UP, "SAS", 1.117, -0.30, "A");  
		createLanguage(12, 10, DELTA_DOWNDOWN, "PL/SQL", 0.971, -0.75, "A");  
		createLanguage(13, 13, DELTA_SAME, "COBOL", 0.741, -0.24, "A");  
		createLanguage(14, 16, DELTA_UPUP, "Lisp/Scheme", 0.658, +0.30, "A-");  
		createLanguage(15, 17, DELTA_UPUP, "VB.NET", 0.614, +0.03, "A-");  
		createLanguage(16, 15, DELTA_DOWN, "ABAP", 0.525, -0.21, "B");  
		createLanguage(17, 18, DELTA_UP, "Pascal", 0.516, -0.05, "B");  
		createLanguage(18, 20, DELTA_UPUP, "Ada", 0.484, +0.02, "B");  
		createLanguage(19, 19, DELTA_SAME, "Fortran", 0.452, -0.05, "B");  
		createLanguage(20, 51, DELTA_UP, "Visual FoxPro", 0.421, +0.36, "B");  
	}
	
	public static void createLanguage(int positionDec2004, int positionDec2005, String delta, 
			String language, double ratingsDec2005, double deltaDec2004, String status){
		Node node = new Node();
		node.setIcon("/demo/resource/images/leaf.gif");
		node.putClientProperty(PositionDec2004, positionDec2004);
		node.putClientProperty(PositionDec2005, positionDec2005);
		node.putClientProperty(Delta, delta);
		node.putClientProperty(Language, language);
		node.putClientProperty(RatingsDec2005, new Double(ratingsDec2005));
		node.putClientProperty(DeltaDec2004, new Double(deltaDec2004));
		node.putClientProperty(Status, status);
		box.addElement(node);

	}
	
	public static Icon getIcon(String delta){
		if(DELTA_UP.equals(delta) || DELTA_UPUP.equals(delta)){
			return TWaverUtil.getIcon("/demo/tree/sort/Up.gif");
		}else if(DELTA_DOWN.equals(delta) || DELTA_DOWNDOWN.equals(delta)){
			return TWaverUtil.getIcon("/demo/tree/sort/Down.gif");
		}else if(DELTA_SAME.equals(delta)){
			return TWaverUtil.getIcon("/demo/tree/sort/Same.gif");
		}
		return null;
	}
	
	public static boolean twoIcon(String delta){
		if(DELTA_DOWNDOWN.equals(delta) || DELTA_UPUP.equals(delta)){
			return true;
		}
		return false;
	}
	

}